﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MailServer.Server
{
    [Serializable]
    public class Data
    {
        private UserList userList;
        private Recipient.Recipient recipient;

        public Data()
        {
            userList = new UserList();
            recipient = new Recipient.Recipient();
        }

        public void AddUser(string user)
        {
            userList.Add(user);
        }

        public bool ContainsUser(string user)
        {
            return userList.Contains(user);
        }

        public void RemoveUser(string user)
        {
            userList.Remove(user);
        }

        public List<string> ListUser() {
            List<string> list = new List<string>();
            for(int i = 0; i < userList.Count(); i++) {
                list.Add(userList.ElementAt(i));
            }
            return list;
        }

        public int GetMessageWaiting(string user)
        {
            return recipient.Count(user);
        }

        public List<Message.Message> GetNewMessages(string user)
        {
            return recipient.ListNew(user);
        }

        public Message.Message GetNextMessage(string user)
        {
            return recipient.GetNextMessage(user);
        }

        public void Post(Message.Message message)
        {
            recipient.Add(message);
        }

        public void RemoveMessage(Message.Message message)
        {
            recipient.Remove(message);
        }
    }
}
